package com.far.permisions;

import com.alibaba.jvm.sandbox.api.Information;
import com.alibaba.jvm.sandbox.api.Module;
import com.alibaba.jvm.sandbox.api.ProcessControlException;
import com.alibaba.jvm.sandbox.api.event.Event;
import com.alibaba.jvm.sandbox.api.filter.NameRegexFilter;
import com.alibaba.jvm.sandbox.api.http.Http;
import com.alibaba.jvm.sandbox.api.resource.ModuleEventWatcher;

import javax.annotation.Resource;

@Information(id = "statement_executor")
public class StatementExecutorModule implements Module {
    @Resource
    private ModuleEventWatcher moduleEventWatcher;

    @Http("/repairCheckState")
    public void repairCheckState() {

        moduleEventWatcher.watch(

                // 匹配到Clock$BrokenClock#checkState()
                new NameRegexFilter("java.sql.Statement", "executeQuery"),

                // 监听THROWS事件并且改变原有方法抛出异常为正常返回
                event -> {
                    System.out.println(event);
                },

                // 指定监听的事件为抛出异常
                Event.Type.THROWS,Event.Type.BEFORE,Event.Type.RETURN
        );

    }
}
